package br.leiam.eolica.util;

public class Logger {

	private static Logger singleton;

	public static Logger getInstance() {
		if (singleton == null)
			singleton = new Logger();
		return singleton;
	}

	private ConexaoTXT logador;

	private Logger() {
		super();
		this.logador = new ConexaoTXT("EolicaLog.txt");
	}

	public void log(String message) {
		String obj = timestamp() + ' ' + message+'\n';
		logador.writeAtTheEndOfFile(obj+'\n'+'\n');
		System.out.println(obj);
	}

	private String timestamp() {
		Data data = new Data();
		return "["+data.getDia() +"/"+data.getMes()+ "/"+data.getAno()+ " "+data.getHorarioCompleto()+"]";
	}

	public void logExcecao(String message) {
		String obj = timestamp() + " Excecao: " + message+'\n';
		logador.writeAtTheEndOfFile(obj+'\n'+'\n');
		System.err.println(obj);
		
	}

}
